import axios from 'axios'
let instance = axios.create({
  baseURL: 'http://gz.wolfcode.cn/cms',
  timeout:5000
});

//http request 拦截器
instance.interceptors.request.use(
  (config) => {
    if (config.url === "/wechatUsers/PCLogin" || config.url === "/sendSMS"|| config.url === "/shop/carts/add") {
      config.headers["Content-Type"] = "application/x-www-form-urlencoded"
    }
    const token = localStorage.getItem("x-auth-token")
    if (token) {
      config.headers["x-auth-token"] = token
    }
    return config
  },
  (err) => {
    return Promise.reject(err)
  }
)

instance.interceptors.response.use(
  (response) => {
    return response.data
  },
  (error) => {
    return Promise.reject(error.response.status)
  }
)

export default instance